<?php

namespace magein\think\migration;

use magein\migration\PhinxInput;
use Phinx\Console\PhinxApplication;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument as InputArgument;
use think\console\Output;

class MigrateCommand extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('migrate:new')
            ->setDescription('Create a new migration')
            ->addArgument('name', InputArgument::REQUIRED, '这次迁移的名称是什么?')
            ->addArgument('run', InputArgument::OPTIONAL, '执行命令,可选')
            ->addArgument('rollback', InputArgument::OPTIONAL, '回滚,可选')
            ->setHelp(sprintf('%sCreates a new database migration%s', PHP_EOL, PHP_EOL));
    }

    protected function execute(Input $input, Output $output)
    {

        $argv = array_slice($_SERVER['argv'], 1);

        $input = new PhinxInput();
        $input->configuratio = __DIR__ . '/phinx.php';
        $app = new PhinxApplication();
        $app->run($input->init($argv));

        $output->writeln('<info>Created completed</info>');
    }
}